home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Over 1,000 Windows 95 Programs
/
Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso
/
1256
/
c_filt.c_
/
c_filt.c
Wrap
C/C++ Source or Header
|
1997-04-18
|
16KB
|
376 lines
/* EasyCODE(C++) V5.1 01.03.1995 16:22:17 */
/* EasyCODE O
If=vertical
LevelNumbers=no
LineNumbers=no
ScreenFont=Courier New,,80,9220,-11,0,400,0,0,0,0,0,0,3,2,1,49
PrinterFont=Courier New,,80,17414,-34,0,400,0,0,0,0,0,0,3,2,1,49
LastLevelId=22 */
/* EasyCODE ( 1
c_filt.c */
#include "c_filt.h" // include header files
/* EasyCODE ( 15
CommentGetChar */
/* EasyCODE F */
char CommentGetChar()
/********************************************************************************************************************
** Function: CommentGetChar
** Parameters: none
** Return: 1 character
** Purpose: Function delivers charecters of a string. This string contains
** the latest line read, but without keyword.
********************************************************************************************************************/
{
return i_buf[ bufPos++];
}
/* EasyCODE ) */
/* EasyCODE ( 16
CommentFilter */
/* EasyCODE F */
int CommentFilter( int *convertReturn, FILE *stream)
/****************************************************************************************************************
** Function: CommentFilter
** Parameters: convertReturn defines the "Return" processing
** output stream
** Return: Integer error code
** Purpose: The function checks whether the line contains (C/C++)-Kommentare enthalten and extracts
** them. Each comment is written to a separate line. If a comment is not closed within the
** the same text (i.e. between the corresponding Text-EndText keys), an error message is
** created. Also if a comment is closed that has no begin, an error message is created.
** Comments are written to the output stream contained in the parameter stream.
** The value of *convertReturn defines the "Return" processing:
** 0: Comment is written "normally" in "Line=..".
** 1: Blanks are inserted between Line= and comment.
** 2: "Return" is inserted between Line= and comment.
****************************************************************************************************************/
{
char ch, last_ch;
int startpos=0; // Variable for comment begin
BOOL readchar = FALSE; // Flag, indicating read ahaed of character
bufPos = 0; // Initialization of actual reading position
cInString = '\0'; // Indicator for position (string, comment, statement).
/* EasyCODE - */
ch = CommentGetChar(); // Read one character
while ((ch != '\0') && (ch != '\r') && (ch != '\n')
/* while not EOL */)
{
if (ch == EOF
/* EOF reached */)
{
return ERROR_EOF /* Return error */;
}
switch (ch
/* action dependent on character read */)
{
case '\"' /* Character read: " */:
if ((! bInBlockComment) && (! bInLineComment)
/* If not within a C or C++ comment */)
{
if (cInString == '\"'
/* Current position within string ".." */)
{
cInString = '\0';
/* close string on second " - reset cInString to \0 */
}
else
{
cInString = '\"';
/* begin of a string */
}
startpos++;
/* Within a string the start position is incremented
because this part is not taken */
}
break;
case '\'' /* Character read: ' */:
if ((! bInBlockComment) && (! bInLineComment)
/* If not within a C or C++ comment */)
{
if (cInString == '\''
/* Current position within string '..' */)
{
cInString = '\0';
/* Bei zweitem auftretenden ' muß der String geschlossen und die
Hilfsvariable cInString auf \0 zurückgesetzt werden */
}
else
{
cInString = '\'';
/* begin of a string */
}
startpos++;
/* Within a string the start position is incremented
because this part is not taken */
}
break;
case '/' /* Character read: / */:
if (cInString == '\0'
/* Current position outside a string ? */)
{
switch (ch = CommentGetChar()
/* Read next character and do appropriate actions */)
{
case '*' /* Character read: * */:
if ((!bInLineComment)
/* Outside C++ comment */)
{
if (!bInBlockComment)
{
bInBlockComment = TRUE;
/* Boolean variable for block comments is now TRUE until
ending mark is reached */
}
else
{
readchar = TRUE;
}
}
break;
case '/'/* Character read: / */:
if (!bInBlockComment
/* Outside block comment */)
{
bInLineComment = TRUE; // Set flag for C++ comments
do
{
last_ch = ch; // Save latest charcter read
ch = CommentGetChar(); // Read next character
}
while (((ch != '\0') && (ch != '\r') && (ch != '\n'))
/* While not EOL */);
switch (*convertReturn
// "Return" processing necessary ?
)
{
case 2 // First line of "Return" statement to be written
:
fputs("Line=Return ", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - 1 - startpos), stream);
fputs("\n",stream);
// Insert "Return" in first "Line=" line before content of line.
*convertReturn = 1;
// Continue with another return processing.
break;
case 1:
fputs("Line= ", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - 1 - startpos), stream);
fputs("\n",stream);
// Insert blanks after "Line=" to achieve proper alignment.
break;
case 0:
fputs("Line=", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - 1 - startpos), stream);
fputs("\n",stream);
/* Write comment without any modifications. */
break;
}
if (last_ch != '\\'
/* Last character before EOL no \ ?*/)
{
bInLineComment = FALSE; // Reset flag.
}
else
{
/* If last character "\", next line is a comment, too. */
}
return NO_ERROR
/* Comment processed successfully */;
}
break;
default:
if ((! (bInBlockComment)) && (! (bInLineComment))
/* If not within a comment */)
{
startpos += 1; // Increment comment position
}
readchar = TRUE; // Set flag for read ahead.
break;
}
}
else
{
startpos++; // Increment comment position if within a string.
}
break;
case '\\' /* Character read: \ */:
if ((! bInBlockComment) && (! bInLineComment)
/* Outside any comment */)
{
ch = CommentGetChar();
/* Skip next character */
/* EasyCODE - */
startpos += 2; // Increment comment position
}
break;
case '*' /* Character read: * */:
if (cInString == '\0')
{
if ((ch = CommentGetChar()) == '/'
/* If next charcter is / */)
{
if (bInBlockComment
/* If within C comment */)
{
switch (*convertReturn
// If "Return" processing necessary
)
{
case 2 // First "Line=" line of a Return statement to be written
:
fputs("Line=Return ", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - startpos), stream);
fputs("\n",stream);
// Insert "Return" in first "Line=" line before content of line.
*convertReturn = 1;
// Continue with another return processing.
break;
case 1:
fputs("Line= ", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - startpos), stream);
fputs("\n",stream);
// Insert blanks after "Line=" to achieve proper alignment.
break;
case 0:
fputs("Line=", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - startpos), stream);
fputs("\n",stream);
/* Write comment without any modifications. */
break;
}
/* Write comment */
/* EasyCODE - */
bInBlockComment = FALSE;
startpos = bufPos;
// Reset flag for C comments.
// Set comment psoition to current position.
}
else
{
if (! bInLineComment
/* If not within a C++ comment */)
{
return ERROR_COMMENT
/* Error message if comment did not start properly. */;
}
else
{
readchar = TRUE; // Unknown character read ahead.
}
}
}
else
{
if (( ! bInBlockComment) && (! bInLineComment)
/* Outside C or C++ comment. */)
{
startpos += 1; // Increment comment psoition.
}
readchar = TRUE; // Unknown character read ahead.
}
}
else
{
startpos++;
}
break;
default:
if ((! bInBlockComment) && (! bInLineComment)
/* Outside C or C++ comment */)
{
startpos++; // Increment comment position.
}
break;
}
if (! readchar
/* No character read ahead */)
{
last_ch = ch; // Save last character (needed for C++ comments).
ch = CommentGetChar(); // Read next character.
}
readchar = FALSE; // Reset flag for read ahead.
}
if (bInBlockComment
/* Within C comment */)
{
/* You'll get here if a C comment is open.
This comment is written to the output file. */
switch (*convertReturn
// "Return" processing necessary
)
{
case 2 // First "Line=" line of a Return statement to be written
:
fputs("Line=Return ", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - 1 - startpos), stream);
fputs("\n", stream);
// Insert "Return" in first "Line=" line before content of line.
*convertReturn = 1;
// Continue with another return processing.
break;
case 1:
fputs("Line= ", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - 1 - startpos), stream);
fputs("\n", stream);
// Insert blanks after "Line=" to achieve proper alignment.
break;
case 0:
fputs("Line=", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - 1 - startpos), stream);
fputs("\n", stream);
/* Write comment without any modifications. */
break;
}
}
if (bInLineComment
/* Within C++ comment */)
{
/* C++ comment has multiple lines;
first line is written to Output file */
switch (*convertReturn
// "Return" processing necessary
)
{
case 2 // First "Line=" line of a Return statement to be written
:
fputs("Line=Return ", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - 1 - startpos), stream);
fputs("\n", stream);
// Insert "Return" in first "Line=" line before content of line.
*convertReturn = 1;
// Continue with another return processing.
break;
case 1:
fputs("Line= ", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - 1 - startpos), stream);
fputs("\n", stream);
// Insert blanks after "Line=" to achieve proper alignment.
break;
case 0:
fputs("Line=", stream);
fwrite( (void*) &i_buf[startpos], sizeof(char), (bufPos - 1 - startpos), stream);
fputs("\n", stream);
/* Write comment without any modifications. */
break;
}
if (last_ch != '\\'
/* Last character in C++ comment not \ */)
{
bInLineComment = FALSE;
/* If last character not \ C++ comment is finished. */
}
}
return NO_ERROR
/* Return value for correct comment processing */;
}
/* EasyCODE ) */
/* EasyCODE ) */